/**
 * @author roua_troua
 */
package q10.GUI;

import q10.ArboriFunctionali;
import q10.Functii.ParantezaStanga;
import q10.Functii.ParantezaDreapta;
import q10.Operatori.*;
import q10.Functii.FunctiiTrigonometrice.*;
import q10.Functii.FunctiiElementare.*;
import q10.Arbori.*;
import java.awt.Dimension;

public class Parsare implements Command{
    private int i = 0;
    private Nod k = null;
    private String sir, sir33="";
    
    //private javax.swing.JLabel err;
    public ArboriFunctionali a = null;

    /**
     * Parsare
     * @param a
     * @param f
     */
    public Parsare(ArboriFunctionali a,String f){ //,javax.swing.JLabel err){
        this.a = a;
        this.sir = f;
       // this.err = err;
    }
    
    /**
     * 
     * @param p
     */
    public void setI(int p){
        this.i = p;
    }

    /**
     * 
     * @return
     */
    public int getI(){
        return i;
    }

    /**
     * 
     * @param sir
     * @return
     */
    public Nod identificare(String sir){
        Nod op = null;
        String sirL = "";
        
        if(i<sir.length()){
           // System.out.println("i = " + i);
            switch(sir.charAt(i))
            {
                case '(':
                    op=new ParantezaStanga("[");
                    break;
                case ')':
                    op=new ParantezaDreapta("]");
                    break;
                case 'x':
                    op=new Necunoscuta("X");
                    break;
                case '+':
                    op=new Plus("+");
                    break;
                case '-':
                    op=new Minus();
                    break;
                case '*':
                    op=new Produs();
                    break;
                case '/':
                    op=new Cat();
                    break;
                case '^':
                    op=new Putere();
                    break;
                case 's':
                    if((i+1 < sir.length()) && sir.charAt(i+1) == 'i' && (i+2 < sir.length()) && sir.charAt(i+2) == 'n')
                    {
                        op=new Sin("SINUS");
                        i = i + 2;
                        sirL = "SINUS";
                    }
                    else {
                        if((i+1 < sir.length()) && sir.charAt(i+1) == 'q' && (i+2 < sir.length()) && sir.charAt(i+2) == 'r' && (i+3 < sir.length()) && sir.charAt(i+3) == 't')
                        {
                            //op = new Sqrt();
                            i = i + 3;
                        }
                    }
                    break;
                case 'c':
                    if((i+1 < sir.length()) && sir.charAt(i+1) == 'o' && (i+2 < sir.length()) && sir.charAt(i+2) == 's')
                    {
                        op=new Cos();
                        i = i + 2;
                        sirL = "COSINUS";
                    }
                    else
                    {
                        if((i+1 < sir.length()) && sir.charAt(i+1) == 't' && (i+2 < sir.length()) && sir.charAt(i+2) == 'g')
                        {
                            op=new Ctg();
                            i = i + 2;
                        }
                    }
                    break;
                case '0':
                    op = new Constanta(0);
                    break;
                case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
                    //i++;
                    double nr = 0;
                    while(i < sir.length() && (sir.charAt(i) == '1' || sir.charAt(i) == '2' || sir.charAt(i) == '3' || sir.charAt(i) == '4' || sir.charAt(i) == '5' || sir.charAt(i) == '6' || sir.charAt(i) == '7' || sir.charAt(i) == '8' || sir.charAt(i) == '9' || sir.charAt(i) == '0'))
                    {
                        nr = nr * 10 + sir.charAt(i) - '0';
                        i++;
                    }
                    if(i < sir.length() && sir.charAt(i) == '.')
                    {
                        int j=0;
                        i++;
                        while((sir.charAt(i) == '1' || sir.charAt(i) == '2' || sir.charAt(i) == '3' || sir.charAt(i) == '4' || sir.charAt(i) == '5' || sir.charAt(i) == '6' || sir.charAt(i) == '7' || sir.charAt(i) == '8' || sir.charAt(i) == '9' || sir.charAt(i) == '0') && i<sir.length())
                        {
                            nr = nr * 10 + sir.charAt(i) - '0';
                            i++;
                            j++;
                        }
                        i--;
                        nr = nr / Math.pow((double)10,(double)j);
                    }
                    i--;
                    op = new Constanta(nr);
                    break;
                case 'p':
                    if(sir.charAt(i) == 'i')
                    {
                        i++;
                        op = new Constanta(3.14);
                    }
                    else {
                        if((i+1 < sir.length()) && sir.charAt(i+1) == 'o' && (i+2 < sir.length()) && sir.charAt(i+2) == 'w')
                        {
                            op = new Putere();
                            i = i + 2;
                        }
                    }
                    break;
                case 'l':
                    if((i+1 < sir.length()) && sir.charAt(i+1) == 'o' && (i+2 < sir.length()) && sir.charAt(i+2) == 'g')
                    {
                        //op=new Log();
                        i = i + 2;
                    }
                    else {
                        if((i+1 < sir.length()) && sir.charAt(i+1) == 'n'){
                            op=new Ln();
                            i++;
                        }
                    }
                    break;
                case 't':
                    if((i+1 < sir.length()) && sir.charAt(i+1) == 'g')
                    {
                        op = new Tg();
                        i++;
                    }
                    break;
                case 'e':
                    if((i+1 < sir.length()) && sir.charAt(i+1) == 'x' && (i+2 < sir.length()) && sir.charAt(i+2) == 'p')
                    {
                        op = new Exp();
                        i = i + 2;
                    }
            }
            i++;
        }
      //  System.out.println("op = " + op);
 //       try{
        	if (op != null){
        		sir33 = sir33 + op.getNume();
        		GUITemplate.jtValX.setText(sir33);
        	}
 ///       }catch(Exception e){
 ///       	e.getMessage();
  //      }
        return op;
    }

    
    /**
     * 
     * @param sir
     * @return
     */
    public Nod expression(String sir){
        if(i == sir.length())
            return k;
        else{
            Nod n = identificare(sir);
            /**
             * Cazul f(x) = constanta or
             * f(x) = constanta operator necunoscuta
             */
            if(n != null && n.toString().contains("Constanta")){
                Nod n1 = identificare(sir);
                if(n1 != null && n1.toString().contains("Operatori")){
                    /**apoi vedem daca urmatorul e necunoscuta*/
                    Nod n2 = identificare(sir);
                    if(n2 != null && n2.toString().contains("Necunoscuta")){
                        /**
                         * adaugam nodul n1 in arbore si care ramura stanga n, ramura dreapta n2.
                         */
                        n1.setfStang(n);
                        n1.setfDrept(n2);
                        k = n1;
                        /**
                         * returnam nodul parinte
                         */
                        return n1;
                    }
                    else {
                        String errMessage = "Eroare. Asteptam un x!";
                        //err.setMaximumSize(new Dimension(errMessage.length(),5));
                        //err.setText(errMessage);
                        System.err.println("Eroare. Asteptam un x!");
                        return null;
                    }
                }
                else {
                    //adaugare in arbore - constanta
                    k = n;
                    i--;
                    return n;
                }
            }
            else
                /**
                 * Cazul f(x) = necunoscuta
                 * sau f(x) = necunoscuta operator constanta
                 */
                if(n.toString().contains("Necunoscuta")){
                    Nod n1 = identificare(sir);
                    if(n1 !=null && n1.toString().contains("Operatori")){
                        Nod n2 = identificare(sir);
                        if(n2 != null && n2.toString().contains("Constanta")){
                            //adaugare in arbore n1 nod, n fiu stang, n2 fiu drept.
                            n1.setfStang(n);
                            n1.setfDrept(n2);
                            k = n1;
                            return n1;
                        }
                        else {
                            String errMessage = "Eroare. Asteptam o constanta!";
                           // err.setMaximumSize(new Dimension(errMessage.length(),5));
                           // err.setText(errMessage);
                            System.err.println("Eroare. Asteptam o constanta!");
                            return null;
                        }
                    }
                    else {
                        //adaugare in arbore necunoscuta
                        k = n;
                        i--;
                        return n;
                    }
                }
                else
                    /**
                     * Cazul f(x) = functie operator functie;
                     */
                    if(n != null && (n.toString().contains("Ln") || n.toString().contains("Exp") || n.toString().contains("Cos") || n.toString().contains("Sin") || n.toString().contains("Tg") || n.toString().contains("Ctg"))) {
                        Nod n1 = identificare(sir);
                        if(n1 != null && n1.toString().contains("ParantezaStanga")){
                            n.setfStang(expression(sir));
                            Nod n2 = identificare(sir);
                            if(n2 != null && n2.toString().contains("ParantezaDreapta")){
                                //adaug in arbore n
                                n1 = identificare(sir);
                                if(n1 != null && n1.toString().contains("Operatori")){
                                    n1.setfStang(n);
                                    n1.setfDrept(expression(sir));
                                    //adaug in arbore n1 cu fiu stang n si fiu drept ce rezulta din expresie.
                                    k = n1;
                                    return n1;
                                }
                                else{
                                    return k;
                                }

                            }
                            else{
                                String errMessage = "Eroare. Asteptam o ')'!";
                               // err.setMaximumSize(new Dimension(errMessage.length(),5));
                               // err.setText(errMessage);
                                System.err.println("Eroare");
                                return null;
                            }
                        }
                        else {
                            String errMessage = "Eroare. Asteptam o '('!";
                            //err.setMaximumSize(new Dimension(errMessage.length(),5));
                            //err.setText(errMessage);
                            System.err.println("Eroare");
                            return null;
                        }

                    }
                    else
                        /**
                         * Cazul f(x) = (functie) operator functie sau
                         * f(x) = (functie) operator (functie) operator functie
                         */
                        if(n != null && n.toString().contains("ParantezaStanga")){
                            Nod n1 = identificare(sir);
                            if(n1 != null && (n1.toString().contains("Ln") || n1.toString().contains("Exp") || n1.toString().contains("Cos") || n1.toString().contains("Sin") || n1.toString().contains("Tg") || n1.toString().contains("Ctg"))) {
                                Nod n2 = identificare(sir);
                                if(n2 != null && n2.toString().contains("ParantezaStanga")){
                                    n1.setfStang(expression(sir));
                                    Nod n3 = identificare(sir);
                                    if(n3 != null && n3.toString().contains("ParantezaDreapta")){
                                        //k = n1;
                                        n2 = identificare(sir);
                                        if(n2 != null && n2.toString().contains("ParantezaDreapta")){
                                            n3 = identificare(sir);
                                            System.out.println("n3 = "+n3);
                                            System.out.println("Am ajuns inainte de produs");
                                            if(n3 != null && n3.toString().contains("Operatori")){
                                                System.out.println("Am ajuns la produs");
                                                n3.setfStang(n1);
                                                n3.setfDrept(expression(sir));
                                                //adaug in arbore n3 cu fiu stang n1;
                                                k = n3;
                                                return n3;
                                            }
                                            else
                                                return k;
                                        }
                                        else {
                                            String errMessage = "Eroare. Asteptam o ')'!";
                              //              err.setMaximumSize(new Dimension(errMessage.length(),5));
                                //            err.setText(errMessage);
                                            System.err.println("Eroare. Asteptam ')'");
                                            return null;
                                        }
                                    }
                                    else {
                                        String errMessage = "Eroare. Asteptam o ')'!";
                                  //      err.setMaximumSize(new Dimension(errMessage.length(),5));
                                    //    err.setText(errMessage);
                                        System.err.println("Eroare.  Asteptam ')'");
                                        return null;
                                    }
                                }
                                else {
                                    String errMessage = "Eroare. Asteptam o '('!";
                                    //err.setMaximumSize(new Dimension(errMessage.length(),5));
                                    //err.setText(errMessage);
                                    System.err.println("Eroare.  Asteptam '('");
                                    return null;
                                }
                                }
                            else {
                                if(n1 != null && n1.toString().contains("Log") || n1.toString().contains("Pow") || n1.toString().contains("Sqrt")){
                                    Nod n2 = identificare(sir);
                                    if(n2 != null && n2.toString().contains("Constanta")){
                                        Nod n3 = identificare(sir);
                                        if(n3 != null && n3.toString().contains("ParantezaStanga")){
                                            n1.setfDrept(expression(sir));
                                            n3 = identificare(sir);
                                            if(n3 != null && n3.toString().contains("ParantezaDreapta")){
                                                n1.setfStang(n2);
                                                n2 = identificare(sir);
                                                if(n2 != null && n2.toString().contains("ParantezaDreapta")){
                                                    n3 = identificare(sir);
                                                    if(n3 != null && n3.toString().contains("Operatori")){
                                                        n3.setfStang(n1);
                                                        n3.setfDrept(expression(sir));
                                                        //adaug in arbore n3 cu fiu stang n1; verificat daca se adauga recursiv functia ca membru drept.
                                                        k = n3;
                                                        return n3;
                                                    }
                                                    else
                                                        return k;
                                        }
                                        else {
                                            String errMessage = "Eroare. Asteptam o ')'!";
                                  //          err.setMaximumSize(new Dimension(errMessage.length(),5));
                                    //        err.setText(errMessage);
                                            System.err.println("Eroare");
                                            return null;
                                        }
                                        }
                                        else {
                                            String errMessage = "Eroare. Asteptam o ')'!";
                                      //      err.setMaximumSize(new Dimension(errMessage.length(),5));
                                        //    err.setText(errMessage);
                                            System.err.println("Eroare");
                                            return null;
                                        }
                                    }
                                    else {
                                        String errMessage = "Eroare. Asteptam o '('!";
                //                        err.setMaximumSize(new Dimension(errMessage.length(),5));
                  //                      err.setText(errMessage);
                                        System.err.println("Eroare");
                                        return null;
                                    }
                                }
                                else {
                                    String errMessage = "Eroare. Asteptam o constanta!";
                    //                err.setMaximumSize(new Dimension(errMessage.length(),5));
                      //              err.setText(errMessage);
                                    System.err.println("Eroare");
                                    return null;
                                }
                                                        }
                            else {
                                String errMessage = "Eroare. Asteptam o functie cunoscuta!";
                        //        err.setMaximumSize(new Dimension(errMessage.length(),5));
                          //      err.setText(errMessage);
                                System.err.println("Eroare");
                                return null;
                            }
                            }
                        }
                        else
                            /**
                             * Cazul f(x) = functie operator (functie)
                             * sau f(x) = functie operator functie operator ... (functie)
                             */
                            if(n != null && (n.toString().contains("Ln") || n.toString().contains("Exp") || n.toString().contains("Cos") || n.toString().contains("Sin") || n.toString().contains("Tg") || n.toString().contains("Ctg"))) {
                                Nod n1 = identificare(sir);
                                if(n1 != null && n1.toString().contains("ParantezaStanga")){
                                    n.setfStang(expression(sir));
                                    Nod n2 = identificare(sir);
                                    if(n2 != null && n2.toString().contains("ParantezaDreapta")){
                                        //adaug in arbore n
                                        n1 = identificare(sir);
                                        if(n1 != null && n1.toString().contains("Operatori")){
                                            n1.setfStang(n);
                                            n2 = identificare(sir);
                                            if(n2 != null && n2.toString().contains("ParantezaStanga")){
                                                n1.setfDrept(expression(sir));
                                                Nod n3 = identificare(sir);
                                                if(n3.toString().contains("ParantezaDreapta")){
                                                    k = n1;
                                                    return n1;
                                                }
                                                else {
                                                    String errMessage = "Eroare. Asteptam o ')'!";
                            //                        err.setMaximumSize(new Dimension(errMessage.length(),5));
                              //                      err.setText(errMessage);
                                                    System.err.println("Eroare");
                                                    return null;
                                                }
                                            }
                                            else {
                                                String errMessage = "Eroare. Asteptam o '('!";
                                //                err.setMaximumSize(new Dimension(errMessage.length(),5));
                                  //              err.setText(errMessage);
                                                System.err.println("Eroare");
                                                return null;
                                            }
                                        }
                                        else {
                                            String errMessage = "Eroare. Asteptam un operator!";
                                    //        err.setMaximumSize(new Dimension(errMessage.length(),5));
                                       //     err.setText(errMessage);
                                            System.err.println("Eroare");
                                            return null;
                                        }
                                    }
                                    else {
                                        String errMessage = "Eroare. Asteptam o ')'!";
                                  //      err.setMaximumSize(new Dimension(errMessage.length(),5));
                                  //      err.setText(errMessage);
                                        System.err.println("Eroare");
                                        return null;
                                    }
                                }
                                else {
                                    String errMessage = "Eroare. Asteptam o '('!";
                     //               err.setMaximumSize(new Dimension(errMessage.length(),5));
                       //             err.setText(errMessage);
                                    System.err.println("Eroare");
                                    return null;
                                }
                                //nu pot avea si functii de tip  log, pow?

                            }
                            else
                                /**
                                 * Cazul f(x) = (functie) *|/|- (functie)
                                 */
                                if(n != null && n.toString().contains("ParantezaStanga")){
                                    Nod n1 = identificare(sir);
                                    if(n1 != null && (n1.toString().contains("Ln") || n1.toString().contains("Exp") || n1.toString().contains("Cos") || n1.toString().contains("Sin") || n1.toString().contains("Tg") || n1.toString().contains("Ctg"))) {
                                        Nod n2 = identificare(sir);
                                        if(n2 != null && n2.toString().contains("ParantezaStanga")){
                                            n1.setfStang(expression(sir));
                                            Nod n3 = identificare(sir);
                                            if(n3 != null && n3.toString().contains("ParantezaDreapta")){
                                                //adaug in arbore n
                                                n2 = identificare(sir);
                                                if(n2 != null && n2.toString().contains("ParantezaDreapta")){
                                                n3 = identificare(sir);
                                                if(n3 != null && (n3.toString().contains("Produs") || n3.toString().contains("Cat") || n3.toString().contains("Minus"))){
                                                    n3.setfStang(n1);
                                                    n2 = identificare(sir);
                                                    if(n2 != null && n2.toString().contains("ParantezaStanga")){
                                                        n3.setfDrept(expression(sir));
                                                        n2 = identificare(sir);
                                                        if(n2 != null && n2.toString().contains("ParantezaDreapta")){
                                                            //adaug in arbore n3 cu fiu stang n1; verificat daca se adauga recursiv functia ca membru drept.
                                                            k = n3;
                                                            return n3;
                                                        }
                                                        else {
                                                            String errMessage = "Eroare. Asteptam o ')'!";
                         //                                   err.setMaximumSize(new Dimension(errMessage.length(),5));
                           //                                 err.setText(errMessage);
                                                            System.err.println("Eroare");
                                                            return null;
                                                        }
                                                    }
                                                    else {
                                                        String errMessage = "Eroare. Asteptam o '('!";
                             //                           err.setMaximumSize(new Dimension(errMessage.length(),5));
                               //                         err.setText(errMessage);
                                                        System.err.println("Eroare");
                                                        return null;
                                                    }
                                                }
                                                else {
                                                    String errMessage = "Eroare. Asteptam * sau / sau -!";
                                 //                   err.setMaximumSize(new Dimension(errMessage.length(),5));
                                   //                 err.setText(errMessage);
                                                    System.err.println("Eroare");
                                                    return null;
                                                }
                                            }
                                            else {
                                                String errMessage = "Eroare. Asteptam o ')'!";
                                     //           err.setMaximumSize(new Dimension(errMessage.length(),5));
                                       //         err.setText(errMessage);
                                                System.err.println("Eroare");
                                                return null;
                                            }
                                            }
                                            else {
                                                String errMessage = "Eroare. Asteptam o ')'!";
                                         //       err.setMaximumSize(new Dimension(errMessage.length(),5));
                                           //     err.setText(errMessage);
                                                System.err.println("Eroare");
                                                return null;
                                            }
                                        }
                                        else {
                                            String errMessage = "Eroare. Asteptam o '('!";
                                 //           err.setMaximumSize(new Dimension(errMessage.length(),5));
                                   //         err.setText(errMessage);
                                            System.err.println("Eroare");
                                            return null;
                                        }
                                        }
                                    else
                                        if(n1 != null && (n1.toString().contains("Log") || n1.toString().contains("Pow") || n1.toString().contains("Sqrt"))){
                                            Nod n2 = identificare(sir);
                                            if(n2 != null && n2.toString().contains("Constanta")){
                                                n = identificare(sir);
                                                if(n != null && n.toString().contains("ParantezaStanga")){
                                                    n1.setfDrept(expression(sir));
                                                    n = identificare(sir);
                                                    if(n != null && n.toString().contains("ParantezaDreapta")){
                                                        n1.setfStang(n2);
                                                        n2 = identificare(sir);
                                                        if(n2 != null && n2.toString().contains("ParantezaDreapta")){
                                                        Nod n3 = identificare(sir);
                                                        if(n3 != null && (n3.toString().contains("Produs") || n3.toString().contains("Cat") || n3.toString().contains("Minus"))){
                                                            n = identificare(sir);
                                                            if(n != null && n.toString().contains("ParantezaStanga")){
                                                                n3.setfStang(n1);
                                                                n3.setfDrept(expression(sir));
                                                                n = identificare(sir);
                                                                if(n != null && n.toString().contains("ParantezaDreapta")){
                                                                //adaug in arbore n3 cu fiu stang n1; verificat daca se adauga recursiv functia ca membru drept.

                                                                k = n3;
                                                                return n3;
                                                                }
                                                                else {
                                                                    String errMessage = "Eroare. Asteptam o ')'!";
                                                                 //   err.setMaximumSize(new Dimension(errMessage.length(),5));
                                                               //     err.setText(errMessage);
                                                                    System.err.println("Eroare");
                                                                    return null;
                                                                }
                                                            }
                                                            else {
                                                                String errMessage = "Eroare. Asteptam o '('!";
                                                             //   err.setMaximumSize(new Dimension(errMessage.length(),5));
                                                           //     err.setText(errMessage);
                                                                System.err.println("Eroare");
                                                                return null;
                                                            }
                                                    }
                                                else {
                                                    String errMessage = "Eroare. Asteptam * sau / sau -!";
                                                    //err.setMaximumSize(new Dimension(errMessage.length(),5));
                                                    //err.setText(errMessage);
                                                    System.err.println("Eroare");
                                                    return null;
                                                }

                                                    }
                                                    else {
                                                        String errMessage = "Eroare. Asteptam o ')'!";
                                                        //err.setMaximumSize(new Dimension(errMessage.length(),5));
                                                        //err.setText(errMessage);
                                                        System.err.println("Eroare");
                                                        return null;
                                                    }
                                                }
                                                else {
                                                    String errMessage = "Eroare. Asteptam o ')'!";
                          //                          err.setMaximumSize(new Dimension(errMessage.length(),5));
                            //                        err.setText(errMessage);
                                                    System.err.println("Eroare");
                                                    return null;
                                                }
                                            }
                                            else {
                                                String errMessage = "Eroare. Asteptam o ')'!";
                              //                  err.setMaximumSize(new Dimension(errMessage.length(),5));
                                //                err.setText(errMessage);
                                                System.err.println("Eroare");
                                                return null;
                                            }
                                        }
                                        else {
                                            String errMessage = "Eroare. Asteptam o constanta!";
                                  //          err.setMaximumSize(new Dimension(errMessage.length(),5));
                                    //        err.setText(errMessage);
                                            System.err.println("Eroare");
                                            return null;
                                        }
                                        }
                                        else {
                                            String errMessage = "Eroare. Asteptam o functie cunoscuta!";
                               //             err.setMaximumSize(new Dimension(errMessage.length(),5));
                                 //           err.setText(errMessage);
                                            System.err.println("Eroare");
                                            return null;
                                        }

                                     }
                                else
                                    /**
                                     * Cazul f(x) = log | pow | sqrt
                                     */
                                    if(n != null && (n.toString().contains("Log") || n.toString().contains("Pow") || n.toString().contains("Sqrt"))){
                                        Nod n1 = identificare(sir);
                                        if(n1.toString().contains("Constanta")){
                                            Nod n2 = identificare(sir);
                                            if(n2.toString().contains("ParantezaStanga")){
                                                n.setfDrept(expression(sir));
                                                Nod n3 = identificare(sir);
                                                if(n3.toString().contains("ParantezaDreapta")){
                                                    n.setfStang(n1);
                                                    k = n;
                                                    return n;
                                                }
                                                else {
                                                    String errMessage = "Eroare. Asteptam o ')'!";
                                                    //err.setMaximumSize(new Dimension(errMessage.length(),5));
                                                    //err.setText(errMessage);
                                                    System.err.println("Eroare");
                                                    return null;
                                                }
                                            }
                                            else {
                                                String errMessage = "Eroare. Asteptam o '('!";
                                                //err.setMaximumSize(new Dimension(errMessage.length(),5));
                                                //err.setText(errMessage);
                                                System.err.println("Eroare");
                                                return null;
                                            }
                                            }
                                        else {
                                            String errMessage = "Eroare. Asteptam o constanta!";
                                            //err.setMaximumSize(new Dimension(errMessage.length(),5));
                                            //err.setText(errMessage);
                                            System.err.println("Eroare");
                                            return null;
                                        }
                                    }



            return expression(sir);
        }
    }

    public ArboriFunctionali execute(){
        a = new ArboriFunctionali(expression(sir));
        return a;
    }
   
    public ArboriFunctionali unexecute(){
        return a;
    }

}